/*
 * @Author: your name
 * @Date: 2024-04-10 17:19:58
 * @LastEditTime: 2024-04-10 17:26:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\150.逆波兰表达式求值.cpp
 */
/*
 * @lc app=leetcode.cn id=150 lang=cpp
 *
 * [150] 逆波兰表达式求值
 */

// @lc code=start
class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<long long> st;
        for(auto token :tokens){
            if(token == "+" || token == "-" || token == "*" || token == "/"){
                long long num2 = st.top();
                st.pop();
                long long num1 = st.top();
                st.pop();
                if(token == "+") st.push(num1+num2);
                if(token == "-") st.push(num1-num2);
                if(token == "*") st.push(num1*num2);
                if(token == "/") st.push(num1/num2);
            }else{
                st.push(stoll(token));
            }
        }
        int res = (int)st.top();
        return res;
    }
};
// @lc code=end

